package com.MedDroid.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.MedDroid.MainApp;
import com.MedDroid.R;
import com.MedDroid.task.LoadEditProfilePageTask;
import com.MedDroid.task.LoadProfilePageTask;
import com.MedDroid.task.SubmitUserChangesTask;

public class EditProfileActivity extends Activity
{
	public Button btnSubmitChanges;
	public TextView EditFirstName, EditLastName, EditMiddleName, EditPhoneNumber, EditAddressLine, EditCity, EditProvince, EditCountry, EditPostalCode, EditEmergencyFullName, EditEmergencyPhoneNumber;
	public int LoadedUser;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.edit_profile);

		Bundle extras = getIntent().getExtras();
		if (extras != null)
		{
			LoadedUser = extras.getInt("UserID");
		}

		EditFirstName = (TextView) findViewById(R.id.txtFirstName);
		EditLastName = (TextView) findViewById(R.id.txtLastName);
		EditMiddleName = (TextView) findViewById(R.id.txtMiddleName);
		EditPhoneNumber = (TextView) findViewById(R.id.txtPhoneNumber);
		EditAddressLine = (TextView) findViewById(R.id.txtAddressLine);
		EditCity = (TextView) findViewById(R.id.txtCity);
		EditProvince = (TextView) findViewById(R.id.txtProvince);
		EditCountry = (TextView) findViewById(R.id.txtCountry);
		EditPostalCode = (TextView) findViewById(R.id.txtPostalCodeProfile);
		EditEmergencyFullName = (TextView) findViewById(R.id.txtEmergencyContact);
		EditEmergencyPhoneNumber = (TextView) findViewById(R.id.txtEmergencyNumberProfile);

		btnSubmitChanges = (Button) findViewById(R.id.btnSubmitProfilePageChange);

        btnSubmitChanges.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                //Process Request To Make user changes
				new SubmitUserChangesTask(((MainApp)getApplication()).getDatabase(),EditProfileActivity.this).execute(LoadedUser);
                finish();
            }
        });

		//TODO Change below to load user selected on previous screen
		LoadedUser = ((MainApp)getApplication()).getAuthentication().getLoginUser().getUserID();
		new LoadEditProfilePageTask(((MainApp)getApplication()).getDatabase(),EditProfileActivity.this).execute(LoadedUser);
    }
}
